package cn.rongdao.jrkabao.ui.main.mainfragment.uicomponent;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRString;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.vip.MemberBean;
import cn.rongdao.jrkabao.ui.main.mainfragment.adapter.MemberPowerAdapter;
import cn.rongdao.jrkabao.ui.webview.WebViewActivity;

/**
 * Created by jack on 2018/1/25
 */

public class MemberPowerUIComponent extends LinearLayout {
    public MemberPowerUIComponent(Context context) {
        super(context);
    }

    public MemberPowerUIComponent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MemberPowerUIComponent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private TextView tvMemberPowerProtocol;
    private RecyclerView powerRecyclerView;

    private MemberPowerAdapter adapter;

    private String linkUrl;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        tvMemberPowerProtocol = findViewById(R.id.lmp_tv_member_power_protocol);
        powerRecyclerView = findViewById(R.id.lmp_recyclerview);

        adapter = new MemberPowerAdapter(getContext());
        powerRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 4));
        powerRecyclerView.setAdapter(adapter);

        tvMemberPowerProtocol.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!FRString.isEmpty(linkUrl)) {
                    WebViewActivity.start(getContext(), linkUrl);
                }
            }
        });
    }

    public void setContent(List<MemberBean.VipPrivilegeBean> dataList) {
        adapter.setDataList(dataList);
    }

    public void setLinkUrl(String linkUrl) {
        this.linkUrl = linkUrl;
    }
}
